import Vue from 'vue'
import App from './pages/App.vue'
import Index from './pages/index.vue'
import notFound from './pages/notFound.vue'
Vue.config.productionTip = false
import VueRouter from 'vue-router'
import store from './store'//引入store

Vue.use(VueRouter)
const routes = [
  { path: '/', component: Index },
  { path: '/app', component: App },
  { path: '/notFound', component: notFound }
]

// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})
router.beforeEach((to, from, next) => {
  if (to.matched.length === 0) { 
    from.name ? next({
      name: from.name
    }) : next('/notFound'); 
  } else {
    next(); //如果匹配到正确跳转
  }
});

new Vue({
  router,
  store
}).$mount("#app")